﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ServiceModel.DomainServices.Client;
using ASPItalia.ModelVirtualCasting.Web.RiaServices;

namespace ASPItalia.ModelVirtualCasting.Silverlight.Data
{
  public class DataManager : IDataManager
  {
    private static Lazy<ModelVirtualCastingDomainContext> _domainContext = new Lazy<ModelVirtualCastingDomainContext>(System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
    public ModelVirtualCastingDomainContext DomainContext { get { return _domainContext.Value; } }

    public DataManager() { }

    public void LoadPeople(Action<LoadOperation<People>> callback)
    {
      EntityQuery<People> _peopleQuery = DomainContext.GetPeopleQuery();
      DomainContext.Load(_peopleQuery, LoadBehavior.RefreshCurrent, callback, null);
    }

    public void LoadMultimediaOfPeople(Action<LoadOperation<Multimedia>> callback, int peopleId)
    {
      EntityQuery<Multimedia> _query = DomainContext.GetMultimediaOfPeopleQuery(peopleId);
      DomainContext.Load(_query, LoadBehavior.RefreshCurrent, callback, null);
    }

    public void UpdatePeople() { DomainContext.SubmitChanges(); }
  }
}
